/*
 * DoCancelaListaAction.java
 *
 * Created on August 7, 2007, 12:23 AM
 */

package br.usp.poli.mfc.struts.action;

import br.usp.poli.mfc.struts.DAO.DAOFactory;
import br.usp.poli.mfc.struts.DAO.ListaDAO;
import br.usp.poli.mfc.struts.actionform.DoInscricaoActionForm;
import br.usp.poli.mfc.struts.bean.Usuario;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
/**
 *
 * @author William T.
 * @version
 */

public class DoCancelaListaAction extends Action {
    
    private final static String NEXT = "cancelaLista";
    
    public ActionForward execute(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        HttpSession session = request.getSession();
        ActionMessages messages = new ActionMessages();
        Usuario loggedUser = (Usuario)session.getAttribute("usuario");
        DoInscricaoActionForm frm = (DoInscricaoActionForm) form;
        ListaDAO listaDAO = DAOFactory.getListaDAO();
        if(frm != null) {
            if(listaDAO.deleteLista(loggedUser.getId_usuario(),frm.getIdRevista())) { // deletou
                System.out.println("DEBUG @ DoCancelaListaAtion :::: Deletou");
                messages.add("log",new ActionMessage("docancelalista.ok"));
                saveErrors(request,messages);
            } else {
                messages.add("log",new ActionMessage("docancelalista.nok"));
                saveErrors(request,messages);
                System.out.println("DEBUG @ DoCancelaListaAtion :::: Deu pau");
            }
            return mapping.findForward(NEXT);
        } else return null; // little POG  
    }
}
